<template>
  <div class="app-container">
    <!-- 添加或修改催缴管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body v-drag-fullscreen>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            <el-form-item label="催缴人" prop="requireUser">
              <el-input v-model="form.requireUser" placeholder="请输入催缴人" :disabled="disabled"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="催缴时间" prop="requireTime">
              <el-date-picker clearable size="small"
                              v-model="form.requireTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择催缴时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="催缴方式" prop="requireType">
              <el-select v-model="form.requireType" placeholder="请选择催缴方式" disabled>
                <el-option
                  v-for="item in dict.require_type"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24" :xs="24">
            <el-form-item label="催缴内容">
              <editor v-model="form.requireContent" :min-height="192" :disabled="disabled"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {addRequirePay, updateRequirePay } from "@/api/payfee/requirePay";
  export default {
    name: "noteFormForm",
    dicts: [   'require_type',   ],
    data() {
      return {
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //是否禁用
        disabled: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {

    },
    methods: {
      show(option){
        this.reset();
        this.disabled = option.type == 'VIEW'
        if(option.type=='ADD'){
          this.form.requireUser = this.$store.state.user.nickName;
          this.form.requireTime = this.parseTime(new Date());
          this.form.requireRecordList = option.requireRecordList;
          this.open = true;
          this.title = "新增催缴管理";
        }
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.$emit("cancel")
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          requireUser: null,
          requireTime: null,
          requireType: '20',
          requireContent: null,
          requireRecordList:[],
        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateRequirePay(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.cancel()
              });
            } else {
              addRequirePay(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.cancel()
              });
            }
          }
        });
      }
    }
  };
</script>
